<template>
  <view v-if="visible" class="msgbox-mask" @touchmove.stop.prevent>
    <view class="msgbox-box">
      <view class="msgbox-title" v-if="title">{{ title }}</view>
      <view class="msgbox-content">{{ content }}</view>
      <view class="msgbox-actions">
        <button v-if="showCancel" class="msgbox-btn cancel" @click="onCancel">{{ cancelText }}</button>
        <button class="msgbox-btn confirm" @click="onConfirm">{{ confirmText }}</button>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, watch } from 'vue'
const props = defineProps({
  modelValue: Boolean,
  title: { type: String, default: '' },
  content: { type: String, default: '' },
  showCancel: { type: Boolean, default: true },
  confirmText: { type: String, default: '确定' },
  cancelText: { type: String, default: '取消' }
})
const emit = defineEmits(['update:modelValue', 'confirm', 'cancel'])
const visible = ref(props.modelValue)

watch(() => props.modelValue, v => visible.value = v)

function onConfirm() {
  visible.value = false
  emit('update:modelValue', false)
  emit('confirm')
}
function onCancel() {
  visible.value = false
  emit('update:modelValue', false)
  emit('cancel')
}
</script>

<style scoped lang="scss">
.msgbox-mask {
  position: fixed;
  left: 0; top: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.25);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.msgbox-box {
  width: 600rpx;
  max-width: 90vw;
  background: #fff;
  border-radius: 24rpx;
  box-shadow: 0 8rpx 32rpx rgba(0,0,0,0.12);
  overflow: hidden;
  padding: 0 0 24rpx 0;
  animation: msgbox-fade-in 0.2s;
}
.msgbox-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #222;
  padding: 36rpx 36rpx 0 36rpx;
  text-align: center;
}
.msgbox-content {
  font-size: 28rpx;
  color: #444;
  padding: 32rpx 36rpx 0 36rpx;
  text-align: center;
  word-break: break-all;
}
.msgbox-actions {
  display: flex;
  justify-content: space-between;
  gap: 32rpx;
  padding: 36rpx 36rpx 0 36rpx;
}
.msgbox-btn {
  flex: 1;
  height: 80rpx;
  border-radius: 16rpx;
  font-size: 30rpx;
  font-weight: 500;
  border: none;
  box-shadow: 0 2rpx 8rpx rgba(255, 126, 45, 0.08);
  transition: background 0.2s, color 0.2s;
}
.cancel {
  background: #f5f5f5;
  color: #888;
}
.confirm {
  background: linear-gradient(90deg, #ffb86c 0%, #ff7e2d 100%);
  color: #fff;
}
@keyframes msgbox-fade-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
</style> 